package com.jetgege.smartbox;

import android.bluetooth.BluetoothDevice;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by JJT-ssd on 2017/3/27.
 */

public class DeviceAdapter extends BaseAdapter {

    List<BluetoothDevice> devices =null;

    public DeviceAdapter(List<BluetoothDevice> devices)
    {
        this.devices=devices;
    }
    @Override
    public int getCount() {
        return devices.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view =null;
        ViewHolder viewHolder=null;
        if (convertView==null)
        {
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(parent.getContext()).inflate(R.layout.popview_device_list_item,parent,false);
            viewHolder.tv_DeviceName=(TextView) view.findViewById(R.id.tv_DeviceName);
            view.setTag(viewHolder);
        }else
        {
            view=convertView;
            viewHolder=(ViewHolder)convertView.getTag();
        }
        viewHolder.tv_DeviceName.setText(devices.get(position).getName());
        return view;
    }

    private class ViewHolder
    {
        TextView tv_DeviceName;
    }
}
